import Vue from 'vue'
import Router from 'vue-router'
import home from './view/home.vue'
import myApprove from "./view/myApprove" //我审批的
import assessment from "./view/assessment" //考核指标
import score from "./view/score" //评分
import ddApi from "@/components/js/ddApi";
import store from "./../store"
Vue.use(Router)

const router = new Router({
  routes: [{
    path: '/',
    name: 'home',
    component: home,
    meta: {
      title: '绩效考核',
      isBelongTo: true, //是否属于钉钉容器中打开
    },
    children: [...myApprove, ...assessment, ...score]
  }]
})

router.beforeEach(async (to, from, next) => {
  const {
    title = '绩效考核',
      isBelongTo = false,
  } = to.meta;

  if (isBelongTo) {
    store.state.navBarTitle = title;
    store.state.navBarRight.title = "";
    if (await ddApi.isDDMobilePlatform()) {
      ddApi.setTitle(title);
      ddApi.setRight(false, false);
    }
  } else {
    if (typeof document !== 'undefined') {
      document.title = title;
    }
  }

  next();
});
export default router;
